<?php

namespace mpend\modules\user\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\user\models\AuthentForm;
use mpend\modules\user\models\UserAuthentView;

/**
 * 身份认证相关接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class AuthentController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            'index' => ['GET'],
            'update' => ['POST'],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * 提交认证
     * @inheritdoc
     */
    public function actionIndex() {
        return UserAuthentView::findByUserId($this->uid);
    }

    /**
     * 提交认证
     * @inheritdoc
     */
    public function actionUpdate() {
        $model = new AuthentForm();
        $model->user_id = $this->uid;
        if (!$model->load(Yii::$app->request->post(), '')) {
            parent::error('请完善信息后提交');
        }
        return $model->save();
    }

}
